/**
 * TemplateAction.java
 *
 * Copyright (c) 2010 Prj.Manager All Rights Reserved.
 *
 * This source file may not be copied, modified or redistributed,
 * in whole or in part, in any form or for any reason, without the express
 * written consent of Prj.Manager .
 **/
package ro.prjmanager.web.actions;

import net.sourceforge.stripes.action.FileBean;
import ro.prjmanager.core.annotations.Column;
import ro.prjmanager.core.annotations.EditOptions;
import ro.prjmanager.core.annotations.Id;
import ro.prjmanager.core.annotations.List;
import ro.prjmanager.core.dao.Filter;
import ro.prjmanager.core.service.SQLQuery;
import ro.prjmanager.model.Template;
import ro.prjmanager.web.annotation.NomenclatorTarget;
import ro.prjmanager.web.annotation.Service;

import javax.servlet.http.HttpServletRequest;

@Service(target = "templateService")
@NomenclatorTarget(addTarget = "add",deleteTarget = "del",editTarget = "edit",
        resource = "/pages/nomenclators/template/template.jsp",
        onFaildReturn = "/pages/nomenclators/template/template.jsp")
@List(serviceName = "templateService",
        caption = "Template List",
        editUrl = "%context_path%/actions/Template.action",
        id = "1", height = 200, rowNum = 10,
        url = "%context_path%/template.lst")
public class TemplateAction extends GenericAction<Template> {

    @Id
    private Long idL;

    @Column(name = "name", caption = "NAME", index = "name", width = 100, editOptions = @EditOptions(pos = 2   ))
    private java.lang.String name;

    @Column(name = "vmFile", caption = "VM_FILE", index = "vmFile", width = 100, editOptions = @EditOptions(pos = 3  , edittype = "file" ))
    private FileBean vmFile;

    @Column(name = "needUpdate", caption = "NEED_UPDATE", index = "needUpdate", width = 100, editOptions = @EditOptions(pos = 4 ,edittype = "checkbox",value = "true:false",defaultValue = "false"))
    private java.lang.String needUpdate;

    @Column(name = "replacer", caption = "REPLACER", index = "replacer", width = 100, editOptions = @EditOptions(pos = 5  ,cols = 20, rows = 4, edittype = "textarea" ))
    private java.lang.String replacer;

    @Column(name = "fileGenExt", caption = "FILE_GEN_EXT", index = "fileGenExt", width = 100, editOptions = @EditOptions(pos = 6   ))
    private java.lang.String fileGenExt;

    @Column(name = "fileGenName", caption = "FILE_GEN_NAME", index = "fileGenName", width = 100, editOptions = @EditOptions(pos = 7  ,cols = 20, rows = 4, edittype = "textarea" ))
    private java.lang.String fileGenName;


    private Long idPersonFunction;

    public Long getIdPersonFunction() {
        return idPersonFunction;
    }

    public void setIdPersonFunction(Long idPersonFunction) {
        this.idPersonFunction = idPersonFunction;
    }

    public Long getIdL() {
        if(getId()!=null&&!getId().isEmpty()&&!getId().equals("_empty"))
          idL=Long.valueOf(getId());
        return idL;
    }

    public void setIdL(Long idL) {
        this.idL = idL;
        if(idL!=null)
            this.setId(String.valueOf(idL));
    }

    /**
     * This method gets the name attribute
     * @return - an  java.lang.String  object
     **/
    public  java.lang.String getName(){
        return this.name;
    }

    /**
     * The setter for the name attribute
     * @param name -  an  java.lang.String object
     **/
    public void setName(java.lang.String  name){
        this.name=name;
    }
    /**
     * This method gets the vmFile attribute
     * @return - an  net.sourceforge.stripes.action.FileBean object
     **/
    public  FileBean  getVmFile(){
        return this.vmFile;
    }

    /**
     * The setter for the vmFile attribute
     * @param vmFile -  an  net.sourceforge.stripes.action.FileBean object
     **/
    public void setVmFile( FileBean  vmFile){
        this.vmFile=vmFile;
    }
    /**
     * This method gets the needUpdate attribute
     * @return - an  java.lang.Integer  object
     **/
    public  java.lang.String  getNeedUpdate(){
        return this.needUpdate;
    }

    /**
     * The setter for the needUpdate attribute
     * @param needUpdate -  an  java.lang.Integer object
     **/
    public void setNeedUpdate( java.lang.String  needUpdate){
        this.needUpdate=needUpdate;
    }
    /**
     * This method gets the replacer attribute
     * @return - an  java.lang.String  object
     **/
    public  java.lang.String getReplacer(){
        return this.replacer;
    }

    /**
     * The setter for the replacer attribute
     * @param replacer -  an  java.lang.String object
     **/
    public void setReplacer(java.lang.String  replacer){
        this.replacer=replacer;
    }
    /**
     * This method gets the fileGenExt attribute
     * @return - an  java.lang.String  object
     **/
    public  java.lang.String getFileGenExt(){
        return this.fileGenExt;
    }

    /**
     * The setter for the fileGenExt attribute
     * @param fileGenExt -  an  java.lang.String object
     **/
    public void setFileGenExt(java.lang.String  fileGenExt){
        this.fileGenExt=fileGenExt;
    }
    /**
     * This method gets the fileGenName attribute
     * @return - an  java.lang.String  object
     **/
    public  java.lang.String getFileGenName(){
        return this.fileGenName;
    }

    /**
     * The setter for the fileGenName attribute
     * @param fileGenName -  an  java.lang.String object
     **/
    public void setFileGenName(java.lang.String  fileGenName){
        this.fileGenName=fileGenName;
    }



    public void add() {
        Template adderObj=getModel();
        
        getService().create(adderObj);

    }
    public void edit() {
         Template editObj=getModel();
        getService().update(editObj);
    }

    public SQLQuery doFilter(SQLQuery query, HttpServletRequest request){
        if(name!=null&&name.length()>0)
            query.addFilter(new Filter("name",name,"c","="));

        return query;
    }

}
